package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.JxbZz;
import service.JxbZzService;

import java.util.List;

/**
 * 疾病症状关联表控制器
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/jxb_zz")
public class JxbZzController {
    @Autowired
    private JxbZzService jxbZzService;

    // 根据疾病ID查询症状关联
    @GetMapping("/jxb/{jxbId}")
    public List<JxbZz> getByJxbId(@PathVariable Integer jxbId) {
        return jxbZzService.findByJxbId(jxbId);
    }

    // 根据症状ID查询疾病关联
    @GetMapping("/zz/{zzId}")
    public List<JxbZz> getByZzId(@PathVariable Integer zzId) {
        return jxbZzService.findByZzId(zzId);
    }

    // 查询疾病-症状关联
    @GetMapping("/{jxbId}/{zzId}")
    public JxbZz getByJxbAndZz(@PathVariable Integer jxbId, @PathVariable Integer zzId) {
        return jxbZzService.findByJxbAndZz(jxbId, zzId);
    }

    // 批量添加关联关系
    @PostMapping("/batch_add")
    public int batchAdd(@RequestBody List<JxbZz> jxbZzList) {
        return jxbZzService.batchAdd(jxbZzList);
    }

    // 添加单个关联关系
    @PostMapping("/add")
    public int add(@RequestBody JxbZz jxbZz) {
        return jxbZzService.add(jxbZz);
    }

    // 更新关联权重
    @PutMapping("/update_weight")
    public int updateWeight(@RequestBody JxbZz jxbZz) {
        return jxbZzService.updateWeight(jxbZz);
    }

    // 删除疾病关联的所有症状
    @DeleteMapping("/jxb/{jxbId}")
    public int deleteByJxbId(@PathVariable Integer jxbId) {
        return jxbZzService.deleteByJxbId(jxbId);
    }

    // 删除症状关联的所有疾病
    @DeleteMapping("/zz/{zzId}")
    public int deleteByZzId(@PathVariable Integer zzId) {
        return jxbZzService.deleteByZzId(zzId);
    }

    // 删除单个关联关系
    @DeleteMapping("/{jxbId}/{zzId}")
    public int deleteByJxbAndZz(@PathVariable Integer jxbId, @PathVariable Integer zzId) {
        return jxbZzService.deleteByJxbAndZz(jxbId, zzId);
    }
}